import { useState, useEffect } from 'react';
import store from '../redux/store';

import { hide, show } from '../redux/action/TabbarActionCreator';

const useAutoHandleTabbar = () => {
  useEffect(() => {
    store.dispatch(hide());
    return () => {
      store.dispatch(show());
    };
  }, []);
};

const useShowBar = () => {
  const [showBar, setShowBar] = useState(
    store.getState().TabbarReducer.showBar
  );
  useEffect(() => {
    let unsubscribe = store.subscribe(() => {
      console.log('useShowBar订阅', store.getState());
      setShowBar(store.getState().TabbarReducer.showBar);
    });
    return () => {
      // 取消订阅
      unsubscribe();
    };
  }, []);

  return {
    showBar,
  };
};

export { useAutoHandleTabbar, useShowBar };
